package com.team1.supervend.domain;

import java.util.HashMap;

public class SuperVend {
	private ProductInventory currentProductInventory;
	private SaleHandler currentSaleHandler;
	Money cashTendered;
	SuperVend superVend;
	ProductInventory superVendProductInventory;
	//PurchaseOrder superVendCurrentPurchaseOrder;
	SaleHandler superVendSaleHandler;
	HashMap<ItemID, ProductDescription> productDescriptions;
	ItemID id;
	int quantity;
	float balance;
	boolean preValidatedCashPayment;
	
	public SuperVend( ){
		//System.out.println("New SuperVend");
		// SuperVend Creates ProductInventory
		CreateProductInventory();

        // SuperVend Provides ProductInventory
		ProvideProductInventory();

		// Stock ProductInventory in SuperVend
		StockProductInventory();

		System.out.println("Welcome to SuperVend");
		System.out.println("--------------------");
		System.out.println(" ");
	}

	public void CreateProductInventory(){
		//System.out.println("SuperVend creates new ProductInventory");
		currentProductInventory = new ProductInventory();
	}
	
	public void ProvideProductInventory(){
		//System.out.println("Supervend Provides ProductInventory");
		currentProductInventory.ProvideProductInventory();
	}
	
	public void StockProductInventory(){
		//System.out.println("Stock ProductInventory in SuperVend");
		currentProductInventory.StockProductInventory();
	}
	
	public void makeNewSaleHandler(){
		currentSaleHandler = new SaleHandler();
	}
	
	public SaleHandler getCurrentSaleHandler(){
		return currentSaleHandler;
	}

	public ProductInventory getCurrentProductInventory()
    {
    	return currentProductInventory;
    }

	public void displayProductInventory( )
	{
		currentProductInventory.printProductDescriptions();
	}

	public void selectItem( int pid, int quantity )
	{
		ItemID id;
		id = getCurrentProductInventory().getItemID(pid);
		ProductDescription desc = currentProductInventory.getProductDescription(id);
		
		currentSaleHandler.getCurrentPurchaseOrder().makeSelectedItem ( desc, quantity );
	}
	
	public void startSale(){
		//show in stock items to customer
		displayProductInventory();
		makeNewSaleHandler();
	}
	
	public void completeSale(){
		currentSaleHandler.completeSale();
	}
	
	public boolean makePayment(Float payment){
		boolean retval = false;
		Money cash = new Money(payment);
		if (currentSaleHandler.getPaymentHandler().makeCashPayment(cash)){
			currentSaleHandler.getCurrentPurchaseOrder().addCash(cash);
			retval = true;
			return retval;
		}
		return retval;
	}

}
